package cn.tedu.store.controller;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.tedu.store.bean.Goods;
import cn.tedu.store.bean.GoodsCategory;
import cn.tedu.store.service.GoodsCategoryService;
import cn.tedu.store.service.GoodsService;

@Controller
@RequestMapping("/main")
public class MainController {
	@Resource
	private GoodsCategoryService goodsCategoryService;
	
	@Resource
	private GoodsService goodsService;
	
	
	@RequestMapping("/showIndex.do")
	public String showIndex(Map<String,Object> map){
		List<GoodsCategory> list1=goodsCategoryService.getGoodsCategoryByParentId(161, 0, 3);
		List<List<GoodsCategory>> list2=new ArrayList<List<GoodsCategory>>();
		for(GoodsCategory c:list1){
			list2.add(goodsCategoryService.getGoodsCategoryByParentId(c.getId(), null, null));
		}
//		System.out.println("二级分类名称：");
//		for(GoodsCategory c:list1){
//			System.out.println(c.getName());
//		}
//		System.out.println("三级分类名称：");
//		for(List<GoodsCategory> list:list2){
//			for(GoodsCategory c:list){
//				System.out.println("\t"+c.getName());
//			}
//		}
		
		//热卖商品
		List<Goods> listGoods=goodsService.getGoodsByCategoryId(163, 0, 3);
				
		//巴特面需要的数据集合，放入集合                                       //List<GoodsCategory>
		map.put("list1", list1);
		map.put("list2",list2);
		map.put("listGoods",listGoods);
		
		return "index";
	}
}
